package com.util;

import java.util.List;

public class StringUtils extends org.apache.commons.lang.StringUtils{

	public static String escapeSql(String str){
		if(str==null) return str;
		str=str.replace("\\", "\\\\").replace("'", "\\'").replace("\"", "\\\"").replace("|", "\\|").replace("&", "\\&")
		.replace("!", "\\!").replace(";", "\\;");
		return str;
	}

	public static <T> String joinBySplit(List<T> list) {
		return joinBySplit(list, ",");
	}

	public static <T> String joinBySplit(List<T> list, String split) {
		StringBuffer sb = new StringBuffer();
		split = StringUtils.isBlank(split) ? "," : split;
		for (T t : list) {
			sb.append((t == null ? "" : t.toString())).append(split);
		}
		if (sb.length() > 0) {
			sb.deleteCharAt(sb.length() - 1);
		}
		return sb.toString();
	}

	public static String joinBySplit(Object[] data) {
		return joinBySplit(data, ",");
	}

	public static String joinBySplit(Object[] data, String split) {
		StringBuffer sb = new StringBuffer();
		split = StringUtils.isBlank(split) ? "," : split;
		for (Object o : data) {
			sb.append((o == null ? "" : o.toString())).append(split);
		}
		if (sb.length() > 0) {
			sb.deleteCharAt(sb.length() - 1);
		}
		return sb.toString();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println(escapeSql("avd\\fgk;klk&;kjkj|sdjfksdf_sdfd'sdf!sdjfksjdf%sdfkj\"sdfs&sdf"));
		StringUtils.isBlank(null);
	}

}
